package com.canglion.ragflow;

import com.canglion.ragflow.auth.AuthManager;
import com.canglion.ragflow.config.RAGFlowConfig;
import com.canglion.ragflow.service.KnowledgeBaseService;
import com.canglion.ragflow.service.WorkflowService;

/**
 * rundreams.blog.csdn.net
 *
 * @Time:2025/9/4
 * @Author: Zihao Zhang
 * @description:
 */

public class RAGFlowClient implements AutoCloseable {

    private final RAGFlowConfig config;
    private final AuthManager authManager;
    private final KnowledgeBaseService knowledgeBaseService;
    private final WorkflowService workflowService;

    public RAGFlowClient(RAGFlowConfig config) {
        this.config = config;
        this.authManager = new AuthManager(config);
        this.authManager.login(); // 首次登录
        this.authManager.startAutoRefresh(); // 自动刷新

        this.knowledgeBaseService = new KnowledgeBaseService(this);
        this.workflowService = new WorkflowService(this);
    }

    // 服务获取方法
    public KnowledgeBaseService kb() {
        return knowledgeBaseService;
    }

    public WorkflowService workflow() {
        return workflowService;
    }

    // 内部访问
    public String getBaseUrl() {
        return config.getBaseUrl();
    }

    public AuthManager getAuthManager() {
        return authManager;
    }

    @Override
    public void close() {
        authManager.shutdown();
    }
}
